package com.virtualfuture.code.hibernate;
// Generated 24-Jan-2008 19:45:54 by Hibernate Tools 3.1.0.beta4
// ARGH

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import static org.hibernate.criterion.Example.create;



import com.virtualfuture.code.test.HibernateUtil;

/**
 * Home object for domain model class Tradehistory.
 * @see com.virtualfuture.code.hibernate.Tradehistory
 * @author Hibernate Tools
 */
public class TradehistoryHome {

    private static final Log log = LogFactory.getLog(TradehistoryHome.class);

    private final SessionFactory sessionFactory = getSessionFactory();
    
    
    
    protected SessionFactory getSessionFactory() {
	 return HibernateUtil.getSessionFactory();
    }
    
    public void persist(Tradehistory transientInstance) {
        log.debug("persisting Tradehistory instance");
        try {
            sessionFactory.getCurrentSession().persist(transientInstance);
            log.debug("persist successful");
        }
        catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }
    
    public void attachDirty(Tradehistory instance) {
        log.debug("attaching dirty Tradehistory instance");
        try {
            sessionFactory.getCurrentSession().saveOrUpdate(instance);
            log.debug("attach successful");
        }
        catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Tradehistory instance) {
        log.debug("attaching clean Tradehistory instance");
        try {
            sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        }
        catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void delete(Tradehistory persistentInstance) {
        log.debug("deleting Tradehistory instance");
        try {
            sessionFactory.getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        }
        catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Tradehistory merge(Tradehistory detachedInstance) {
        log.debug("merging Tradehistory instance");
        try {
            Tradehistory result = (Tradehistory) sessionFactory.getCurrentSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        }
        catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }
    
    public Tradehistory findById( int id) {
        log.debug("getting Tradehistory instance with id: " + id);
        try {
            Tradehistory instance = (Tradehistory) sessionFactory.getCurrentSession()
                    .get("com.virtualfuture.code.hibernate.Tradehistory", id);
            if (instance==null) {
                log.debug("get successful, no instance found");
            }
            else {
                log.debug("get successful, instance found");
            }
            return instance;
        }
        catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List<Tradehistory> findByExample(Tradehistory instance) {
        log.debug("finding Tradehistory instance by example");
        try {
            List<Tradehistory> results = (List<Tradehistory>) sessionFactory.getCurrentSession()
                    .createCriteria("com.virtualfuture.code.hibernate.Tradehistory")
                    .add( create(instance) )
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        }
        catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    } 

}